home *** CD-ROM | disk | FTP | other *** search
- /* --------------------------------------------------------------------------
- * Copyright 1992 by Forschungszentrum Informatik (FZI)
- *
- * You can use and distribute this software under the terms of the licence
- * you should have received along with this program.
- * If not or if you want additional information, write to
- * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
- * D-7500 Karlsruhe 1, Germany.
- * --------------------------------------------------------------------------
- */
- // **************************************************************************
- // Module err Bernhard Schiefer (bs)
- // Juergen Uhl (ju
- // Dietmar Theobald (dt)
- // **************************************************************************
- // SOS error handler
- // **************************************************************************
-
- #include <stream.h>
- #include <libc.h>
- #include <string.h>
- #include "trc_err.h"
- #include "sys.h"
- #include "err.h"
-
- void (*err_output_handler)() = NULL;
-
- const err_msg err_NOT_IMPLEMENTED="attempt to execute not implemented function";
- const err_msg err_ABSTRACT_METHOD="attempt to execute an abstract method";
- const err_msg err_ASSERTION_FAILED="assertion failed";
-
- static int err_sys_sum = 0;
- static int err_use_sum = 0;
- static int err_wng_sum = 0;
-
- static err_class last_class = err_SYS;
- static err_msg last_raised = NULL;
- static char *last_origin = NULL;
-
- class err_buffer
- { char *buf;
- int size;
-
- public:
- err_buffer() { buf = NULL; size = 0; }
-
- char *buffer_string (char *str);
- };
-
- static err_buffer err_raised_buffer;
- static err_buffer err_origin_buffer;
-
- err_env_stc *err_env_stack;
-
- // --------------------------------------------------------------------------
-
- char *err_buffer::buffer_string (char *str)
- { if (str)
- { int strsize = strlen (str) + 1;
-
- if (strsize > size)
- { if (buf)
- delete buf;
- buf = new char[strsize];
- size = strsize;
- }
- return strcpy (buf, str);
- }
- else
- return NULL;
- }
-
- void err_raise (err_class ec, err_msg msg, char* where, int copy)
- {
- T_PROC ("err_raise");
- TT (err_H, T_ENTER; TI (ec));
-
- if (copy)
- { last_raised = err_raised_buffer.buffer_string (msg);
- last_origin = err_origin_buffer.buffer_string (where);
- }
- else
- { last_raised = msg;
- last_origin = where;
- }
- last_class = ec;
-
- if (ec != err_SYS OR NOT err_env_stack)
- if (err_output_handler)
- (*err_output_handler)();
- else
- {
- cerr << ((ec == err_WNG) ? " Warning "
- : " ERROR ");
- if (where)
- {
- cerr << ((ec == err_WNG) ? "for "
- : "in ")
- << where << " ";
- }
- cerr << ": " << msg << "\n";
- cerr.flush();
- }
-
- switch (ec)
- {
- case err_SYS : err_sys_sum++;
- if (err_env_stack)
- siglongjmp (err_env_stack->env, 1);
- else
- abort();
- case err_USE : err_use_sum++; break;
- case err_WNG : err_wng_sum++; break;
- } // switch
-
- TT (err_H, T_LEAVE);
- }
-
- err_class err_last_class ()
- { return last_class;
- }
-
- err_msg err_last_raised ()
- { return last_raised;
- }
-
- err_msg err_last_origin ()
- { return last_origin;
- }
-
- int err_occurred (err_class ec)
- {
- T_PROC ("err_occurred");
- TT (err_H, T_ENTER; TI (ec));
-
- switch (ec)
- {
- case err_SYS : TT (err_H, T_LEAVE; TI (err_sys_sum)); return err_sys_sum;
- case err_USE : TT (err_H, T_LEAVE; TI (err_use_sum)); return err_use_sum;
- case err_WNG : TT (err_H, T_LEAVE; TI (err_wng_sum)); return err_wng_sum;
- } // switch
- }
-
- void err_reset ()
- { err_sys_sum = 0;
- err_use_sum = 0;
- err_wng_sum = 0;
- }
-
- void err_push_env()
- { err_env_stc *es = new err_env_stc;
-
- es->next = err_env_stack;
- err_env_stack = es;
- }
-
- void err_pop_env()
- { err_env_stc *es = err_env_stack;
-
- err_env_stack = err_env_stack->next;
- delete es;
- }
-